package com.tz.service;

import com.tz.entity.FaqItem;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by robin on 2016/8/5 0005.
 */
@Repository
@Transactional
public class FaqServiceImpl implements FaqService {

    @Autowired
    private SessionFactory sessionFactory;

    private Session getSession() {
        return sessionFactory.getCurrentSession();
    }


    @Override
    public void save(FaqItem item) {
        getSession().save(item);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<FaqItem> getAll() {
        String hql = "select f from FaqItem f";
        return getSession().createQuery(hql).list();
    }
}
